<template>
  <div class="inner">
    <div v-if="right">
      <div class="title">
        <p v-if="$route.query.orderId == '制度建设'">制度建设</p>
        <p v-if="$route.query.orderId == '宣教活动'">宣教活动</p>
        <p v-if="$route.query.orderId == '践行社会主义核心价值观'">践行社会主义核心价值观</p>
      </div>
      <div v-show="!btn_show" style="position:absolute;top:40%;left:50%;">
        <p>抱歉,您无权访问</p>
      </div>
      <div class="center">
        <div class="main_content">
          <div
            @click="look(newxx[0].id)"
            class="lz_left"
            style="width:335px;height:209px"
            :style="{backgroundImage:`url(${IP}${newxx[0].thumb})`}"
          ></div>
          <div class="zs_k" @click="look(newxx[0].id)">
            <p class="zs_title">
              {{
              newxx[0].title.length > 20
              ? newxx[0].title.substr(0, 20) + "..."
              : newxx[0].title
              }}
            </p>
            <span v-if="newxx[0].description" class="zs_content">
              {{
              newxx[0].description.length > 20
              ? newxx[0].description.substr(0, 60) + "..."
              : newxx[0].description
              }}
            </span>
            <p class="more" v-show="btn_show">查看更多</p>
          </div>
        </div>
        <div class="second_content">
          <ul>
            <li @click="look(item.id)" v-for="(item, index) of currentPageData" :key="index">
              <p>{{ item.title }}</p>
              <span>{{ item.inputtime.slice(0, 10) }}</span>
            </li>
          </ul>
        </div>
      </div>

      <div id="page">
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :pager-count="5"
          :page-size="pageSize"
          layout="  prev, pager, next"
          :total="this.productList.length"
        ></el-pagination>
      </div>
    </div>

    <!-- <zhiyuanzhezhijiadetail :message="message" ></zhiyuanzhezhijiadetail> -->
  </div>
</template>
<script>
import { Permission } from "../../api/login.js";
export default {
  data() {
    return {
      // message: [{}],
      right: true,
      newxx: [{ thumb: "", title: "" }],
      productList: [{}], //所有数据
      totalPage: 1, // 统共页数，默认为1
      currentPage: 1, //当前页数 ，默认为1
      pageSize: 10, // 每页显示数量
      currentPageData: [], //当前页显示内容
      btn_show: true,
    };
  },
  props: ["id"],

  components: {
    //   zhiyuanzhezhijiadetail:zhiyuanzhezhijiadetail
  },
  mounted() {
    this.setCurrentPageData();
    this.new();
  },
  methods: {
    look(id) {
      if (this.$router.history.current.query.zhuanlan == "zhidujianshe") {
        this.sort = 38;
      } else if (
        this.$router.history.current.query.zhuanlan == "xuanjiaohuodong"
      ) {
        this.sort = 47;
      } else if (this.$router.history.current.query.zhuanlan == "jxshzyhxjzg") {
        this.sort = 48;
      }
      this.$router
        .push({
          path: `/zhidujianshe/zhidujianshe2detail?id=${id}`,
          query: {
            orderId: this.$router.history.current.query.orderId,
            num: this.$router.history.current.query.num,
            sort: this.sort,
          },
        })
        .catch((err) => {
          err;
        });
    },
    new() {
      let self = this;
      Permission(this.$router.history.current.query.num, this).then((res) => {
        if (res) {
          self.$api
            .get(
              `${self.tableList}${this.$router.history.current.query.zhuanlan}-1-1`
            )
            .then((res) => {
              self.newxx = res.data.page.list;
            });
        } else {
          self.btn_show = false;
        }
      });
    },
    // 设置当前页面数据，对数组操作的截取规则为[0~10],[10~20]...,
    setCurrentPageData() {
      let self = this;
      Permission(this.$router.history.current.query.num, this).then((res) => {
        if (res) {
          self.$api
            .get(
              `${self.tableList}${this.$router.history.current.query.zhuanlan}-1-1000000`
            )
            .then((res) => {
              // 计算一共有几页
              self.totalPage = Math.ceil(
                self.productList.length / self.pageSize
              );
              // 计算得0时设置为1
              self.totalPage = self.totalPage == 0 ? 1 : self.totalPage;
              self.productList = res.data.page.list;
              self.productList.splice(0, 1);
              let begin = (self.currentPage - 1) * self.pageSize;
              let end = self.currentPage * self.pageSize;
              //当前页的数据等于
              self.currentPageData = self.productList.slice(begin, end);
            });
        } else {
          self.btn_show = false;
        }
      });
    },
    handleCurrentChange(val) {
      if (val != this.currentPage) {
        this.currentPage = val;
      }

      // this.page = val;
      this.setCurrentPageData(
        `${this.tableList}${this.$router.history.current.query.zhuanlan}-1-1000000`
      );
    },
  },

  watch: {
    $route(to, from) {
      if (
        to.query.zhuanlan == "zhidujianshe" ||
        to.query.zhuanlan == "xuanjiaohuodong" ||
        to.query.zhuanlan == "jxshzyhxjzg"
      ) {
        this.currentPage = 1;
        this.new();
        this.setCurrentPageData();
      }
    },
  },
};
</script>
<style scoped>
.gwgk.content {
  display: flex;
  justify-content: space-between;
  color: #4e4b4b;
  max-width: 1200px;
  margin: auto;
  line-height: 40px;
  padding-top: 90px;
  box-sizing: border-box;
}
.title > p {
  padding-left: 35px;
  margin-bottom: 10px;
}
.gwgk .title {
  font-size: 30px;
  border-bottom: 2px solid rgb(107, 128, 173);
  color: rgb(107, 128, 173);
}
.lz_left {
  background-repeat: no-repeat;
  background-position: top;
  background-size: contain;
}
.gwgk li {
  list-style: none;
}
.gwgk ul,
li,
p {
  padding: 0px;
  margin: 0px;
}

.gwgk .right {
  background: rgb(230, 230, 230);
  width: 980px;
  height: 1190px;
  padding: 0 30px 0;
  box-sizing: border-box;
}

.gwgk .blue {
  color: rgb(25, 67, 119);
}
.zs_k {
  width: 50%;
  display: flex;
  flex-direction: column;

  margin-left: 68px;
}
.zs_title {
  font-weight: bold;
  font-size: 16px;
  color: #333333;
  margin-bottom: 25px;
}
.zs_content {
  font-size: 14px;
  color: #666666;
  line-height: 30px;
  margin-bottom: 20px;
}
.right .inner .more {
  color: white;
  background: #4e69a1;
  width: 195px;
  height: 40px;
  border-radius: 5px;
  text-align: center;
  font-size: 16px;
  line-height: 40px;
}
.more,
.zs_content,
.zs_title,
.main_content img {
  cursor: pointer;
}

.right .inner {
  padding-top: 5px;
  padding-bottom: 80px;
}
.right .inner .main_content {
  display: flex;
  padding: 30px 35px 20px;
}
.second_content {
  height: 592px;
}
.right .inner .second_content li {
  display: flex;
  padding: 25px 35px 15px;
  width: 900px;
  font-size: 16px;
  box-sizing: border-box;
  justify-content: space-between;
  border-top: 1px solid rgb(216, 216, 216);
  color: black;
  cursor: pointer;
}
.right .inner .second_content li:last-child {
  border-bottom: 1px solid rgb(216, 216, 216);
}
.bread {
  max-width: 1150px;
  margin: auto;
  height: 60px;
}
/*馆务公开 新闻咨询 */
.gwgk span {
  display: block;
}
.title_top {
  text-align: center;
}
.xwzx_title {
  color: #060606;
  font-size: 24px;
  margin-top: 20px;
}
.xwzx_second_title {
  font-size: 16px;
  color: #3e3e3e;
  margin-bottom: 10px;
}

.ziti {
  font-size: 16px;
  color: #666666;
}
/* fenye */
#page {
  text-align: center;
  margin-top: 65px;
}
#page >>> .el-pager li {
  border: 1px solid gray;
  margin-right: 20px;
  min-width: 25px;
  height: 25px;
  border-radius: 2px;
}
#page >>> .el-pager li.active {
  color: white;
  cursor: default;
  background: rgb(78, 105, 161);
}
#page >>> .el-icon-arrow-right::before,
#page >>> .el-icon-arrow-left::before {
  content: "";
}
#page >>> .el-pagination .btn-next,
#page >>> .el-pagination .btn-prev {
  height: 40px;
  background: url("../../assets/image/fenye_right.png") no-repeat;
  background-size: auto 30px;
}

#page >>> .el-pagination .btn-prev {
  background: url("../../assets/image/fenye_left.png") no-repeat;
  background-size: auto 30px;
}
</style>
